﻿Public Class frmQuanLy
    Dim MaNV As String
    Dim TenDN As String
    Dim Role As String = ""
    Public Sub ganTT(ByVal maNV As String, ByVal tenDN As String, ByVal role As String)
        Me.MaNV = maNV
        Me.TenDN = tenDN
        Me.lbDN.Text = "Xin chào " + tenDN
        Me.Role = role
    End Sub
    Public Function LayMaNV() As String
        Return MaNV
    End Function
    Private Sub QuanLy_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        btnDangXuat.Enabled = False
        btnChangePass.Enabled = False
        AnTap()
        DisableButton()
        Dim frm As New frmDangNhap()
        frm.ShowDialog()
        If (lbDN.Text <> "Bạn chưa đăng nhập.") Then
            KiemTra()
        End If
    End Sub
    Public Sub KiemTra()
        If (Role <> "") Then
            btnDangXuat.Enabled = True
            btnChangePass.Enabled = True
            btnDangNhap.Enabled = False
            If (Role = "QL") Then
                ChucNangQL()
            ElseIf (Role = "NV") Then
                ChucNangNV()
                btnxKhachHang.Focus()
            End If
        End If
    End Sub
    Private Sub ChucNangNV()
        btnxLapBaoCao.Enabled = True
        btnxDangTin.Enabled = True
        btnxKhachHang.Enabled = True
        btnxTimKiem.Enabled = True
    End Sub
    Private Sub ChucNangQL()
        btnxQLKhachHang.Enabled = True
        btnxQLNhanVien.Enabled = True
        btnxQLTinChoThue.Enabled = True
        btnxQLPhieuThue.Enabled = True
        btnxBackup.Enabled = True
        btnxImport.Enabled = True
        btnxExport.Enabled = True
    End Sub

    Private Sub AnTap()
        tabTiepNhanKH.Visible = False
        tabQLKH.Visible = False
        tabQLNV.Visible = False
        tabQLTinDang.Visible = False
        tabQLPhieuThue.Visible = False
        tabDangTin.Visible = False
        tabBackup.Visible = False
        tabTimKiem.Visible = False
        tabExport.Visible = False
        tabImport.Visible = False
        tabLapBaoCao.Visible = False
    End Sub
    Private Sub DisableButton()
        btnxBackup.Enabled = False
        btnxDangTin.Enabled = False
        btnxExport.Enabled = False
        btnxImport.Enabled = False
        btnxKhachHang.Enabled = False
        btnxLapBaoCao.Enabled = False
        btnxQLKhachHang.Enabled = False
        btnxQLNhanVien.Enabled = False
        btnxQLTinChoThue.Enabled = False
        btnxQLPhieuThue.Enabled = False
        btnxTimKiem.Enabled = False
    End Sub

    Private Sub btnxQLKhachHang_Click(sender As System.Object, e As System.EventArgs) Handles btnxQLKhachHang.Click
        AnTap()
        tabQLKH.Visible = True
    End Sub

    Private Sub btnDangNhap_Click(sender As System.Object, e As System.EventArgs) Handles btnDangNhap.Click
        Dim frm As New frmDangNhap()
        frm.ShowDialog()
    End Sub

    Private Sub btnDangXuat_Click(sender As System.Object, e As System.EventArgs) Handles btnDangXuat.Click
        lbDN.Text = "Bạn chưa đăng nhập."
        Role = ""
        AnTap()
        DisableButton()
        btnDangNhap.Enabled = True
        btnDangXuat.Enabled = False
        btnChangePass.Enabled = False
    End Sub

    Private Sub btnxKhachHang_Click(sender As System.Object, e As System.EventArgs) Handles btnxKhachHang.Click
        AnTap()
        tabTiepNhanKH.Visible = True
    End Sub

    Private Sub btnxDangTin_Click(sender As System.Object, e As System.EventArgs) Handles btnxDangTin.Click
        AnTap()
        tabDangTin.Visible = True
    End Sub

    Private Sub btnxTimKiem_Click(sender As System.Object, e As System.EventArgs) Handles btnxTimKiem.Click
        AnTap()
        tabTimKiem.Visible = True
    End Sub

    Private Sub btnxQLNhanVien_Click(sender As System.Object, e As System.EventArgs) Handles btnxQLNhanVien.Click
        AnTap()
        tabQLNV.Visible = True
    End Sub

    Private Sub btnxQLTinChoThue_Click(sender As System.Object, e As System.EventArgs) Handles btnxQLTinChoThue.Click
        AnTap()
        tabQLTinDang.Visible = True
    End Sub

    Private Sub btnxLapBaoCao_Click(sender As System.Object, e As System.EventArgs) Handles btnxLapBaoCao.Click
        AnTap()
        tabLapBaoCao.Visible = True
    End Sub

    Private Sub btnxBackup_Click(sender As System.Object, e As System.EventArgs) Handles btnxBackup.Click
        AnTap()
        tabBackup.Visible = True
    End Sub

    Private Sub btnxExport_Click(sender As System.Object, e As System.EventArgs) Handles btnxExport.Click
        AnTap()
        tabExport.Visible = True
    End Sub

    Private Sub btnxImport_Click(sender As System.Object, e As System.EventArgs) Handles btnxImport.Click
        AnTap()
        tabImport.Visible = True
    End Sub

    Private Sub btnThoat_Click(sender As System.Object, e As System.EventArgs) Handles btnThoat.Click
        Dim result = MessageBox.Show("Bạn có muốn thoát chương trình không?", "THÔNG BÁO", MessageBoxButtons.YesNo)
        If result = DialogResult.No Then

        ElseIf result = DialogResult.Yes Then
            Me.Close()
        End If
    End Sub

    Private Sub btnxQLPhieuThue_Click(sender As System.Object, e As System.EventArgs) Handles btnxQLPhieuThue.Click
        AnTap()
        tabQLPhieuThue.Visible = True
    End Sub

    Private Sub btnChange_Click(sender As System.Object, e As System.EventArgs) Handles btnChangePass.Click
        Dim frm As New frmNVSetPass
        frm.GanTT(MaNV, TenDN)
        frm.ShowDialog()
    End Sub
End Class